// JavaScript Document
//Takes radius of circle and number of points as arguments, returns array of coordinates
function circlepointgenerator(radius,nrpts)
{
    var edgeoffset = 10;
    var fillradius = radius-edgeoffset;
    var offset = radius*Math.PI/nrpts;
    var arrx = new Array();
    var arry = new Array();
    var coordarray = new Array();

    var q = Math.random() * (Math.PI * 2);
    var r = Math.sqrt(Math.random());
    var x = (fillradius * r) * Math.cos(q);
    var y = (fillradius * r) * Math.sin(q);
    arrx[0] = x;
    arry[0] = y;
    coordarray[0] = new Coordinate(x,y);
	
    //Start Generating Points
    for(var j = 1; j < nrpts; j++)
    {
        var test = 1;
        while (test > 0)
        {
            var q = Math.random() * (Math.PI * 2);
            var r = Math.sqrt(Math.random());
            var x = (fillradius * r) * Math.cos(q);
            var y = (fillradius * r) * Math.sin(q);
            test = 0;
            //Check if point lies within radius of other points
            for(k = 0; k < j; k++)
            {
                if( Math.sqrt(Math.pow(x-arrx[k],2)+Math.pow(y-arry[k],2)) < offset)
                {
                test = 1;
                }
            }
        }
	
        arrx[j] = x;
        arry[j] = y;
        coordarray[j] = new Coordinate(x,y);
	
    }

    return coordarray;

}